Skip to content

[https://nvbugs/6482566][fix] Make MoE all-to-all completion-flag timeout phase-aware - #17376

Merged
xwang233 merged 4 commits into
NVIDIA:mainfrom
xwang233:xiaow/nvbug6482566-moe-a2a-warmup-timeout
Aug 8, 2026
Merged

xwang233 merged 4 commits into
NVIDIA:mainfrom
xwang233:xiaow/nvbug6482566-moe-a2a-warmup-timeout

Conversation

@xwang233

@xwang233 xwang233 commented Aug 6, 2026 •

Copy link
Copy Markdown
Collaborator

Description

The MoE all-to-all dispatch/combine kernels wait for every peer's completion flag under a hardcoded ~300 s device-side deadline and execute trap; when it expires, which poisons the CUDA context of every waiting rank.

No collective separates a rank's first-touch JIT/autotune work from its dispatch launch, so that device-side budget is in effect a deadline on the slowest peer's host-side progress through its first forward. During startup warmup a rank can legitimately spend minutes in one-time work (CuTe DSL compilation, autotuning, module loading). When one does, its peers trap — a survivable slow start becomes a fatal crash for the whole worker.

Reported symptom: N-1 ranks print
dispatch: ---Rank X timed out waiting for completion flag from rank Y
and fail with CUDA_ERROR_LAUNCH_FAILED, while the blamed rank shows no error at all.

Fixes nvbugs/6482566.

Changes

  • Runtime completion-flag budget. The timeout becomes a value carried in the kernel params rather than a compile-time constant, resolved by moeA2AGetTimeoutCycles(). Steady state is unchanged at 300 s; warmup uses 1800 s, the same order of magnitude as torch.distributed's default collective timeout. Overridable via TRTLLM_MOE_A2A_TIMEOUT_SEC / TRTLLM_MOE_A2A_WARMUP_TIMEOUT_SEC.
  • Phase selection. New trtllm::moe_a2a_set_warmup op, driven from the is_warmup setter — the single choke point every warmup transition passes through — so the elevated budget cannot latch on into steady state. Builds without the op degrade to the previous behaviour.
  • CUDA-graph capture is wrapped so captured graphs bake in the steady-state budget. The timeout is a launch argument, so it would otherwise be frozen at warmup's relaxed value for the life of the process.
  • Indexer-Q prewarm. The DSv4 indexer-Q CuTe DSL kernels are compiled before the first collective-bearing forward. This removes the largest single contributor to the skew but is a partial mitigation only — other first-touch compiles sit on the all-to-all path itself and cannot be pre-compiled this way, which is why the runtime budget is the primary fix.

Test Coverage

tests/unittest/_torch/misc/test_moe_a2a_warmup_timeout.py (new, CPU-only):

  • the phase selector forwards the value to the op;
  • a build without the op does not break startup;
  • CUDA-graph capture selects steady state and restores warmup afterwards;
  • regression: the is_warmup setter switches the budget in both directions, so it cannot latch on after warmup.

End-to-end validation used fault injection on GB200 and GB300: delaying one rank by 600 s inside the first warmup forward reproduces the reported signature exactly (N-1 peers timing out in dispatch, all naming the delayed rank) under the 300 s budget, and starts cleanly under the new warmup budget.

Notes for reviewers

  • Steady-state behaviour is intentionally unchanged; only the warmup window and the new env overrides alter the deadline.
  • The budget is passed as a kernel launch argument. A device-resident value would let the spin loop observe phase changes live and would be phase-accurate under CUDA graphs; that is a larger change to the kernel inner loop and is deliberately left as follow-up, with capture pinned to steady state in the meantime.
  • Replacing trap; with a recoverable error path is a separate, larger piece of work: after a timeout the receive buffers are incomplete and the flag generation would need invalidating across ranks. Not attempted here.

PR Checklist

  • PR title follows [JIRA/NVBugs ID][type] Summary
  • Commit is DCO signed off
  • New unit tests added for the fixed behaviour
  • CI green (draft — pending)

Dev Engineer Review

  • Added configurable MoE all-to-all timeout budgets.
  • Uses 300 seconds in steady state and 1,800 seconds during warmup.
  • Supports TRTLLM_MOE_A2A_TIMEOUT_SEC and TRTLLM_MOE_A2A_WARMUP_TIMEOUT_SEC.
  • Added moe_a2a_set_warmup(bool) with compatibility handling for unavailable native bindings.
  • Uses the steady-state timeout during CUDA-graph capture.
  • Prewarms DeepSeek-V4 indexer-Q CuTe DSL kernels before collective-bearing forwards.
  • Propagates timeout cycles through dispatch and combine parameters.
  • Fault-injection validation covered delayed ranks on GB200 and GB300.
  • Review should verify environment-value validation, default handling, atomic state transitions, and unavailable-binding behavior.

QA Engineer Review

  • Added tests/unittest/_torch/misc/test_moe_a2a_warmup_timeout.py.
  • Added:
    • test_set_warmup_forwards_value_to_op
    • test_missing_op_is_tolerated
    • test_capture_context_selects_steady_state_then_restores
    • test_is_warmup_setter_switches_budget_both_ways
  • The test file has no matching entry in tests/integration/test_lists/, test-db/, or qa/.
  • Verdict: needs follow-up.

@xwang233
xwang233 marked this pull request as ready for review August 6, 2026 19:42
@xwang233
xwang233 requested review from a team as code owners August 6, 2026 19:42
@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 86d4e52d-2b59-47db-b9a6-f429926aeb21

📥 Commits

Reviewing files that changed from the base of the PR and between 916b2ac and 8051b69.

📒 Files selected for processing (1)
  • tensorrt_llm/_torch/pyexecutor/model_engine.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tensorrt_llm/_torch/pyexecutor/model_engine.py

Walkthrough

The change adds configurable steady-state and warmup timeout budgets for MoE all-to-all operations. It adds atomic warmup-state control, CUDA graph integration, DeepSeek-V4 indexer-Q prewarming, and unit tests.

Changes

MoE all-to-all timeout and warmup control

Layer / File(s) Summary
Timeout contract and kernel propagation
cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h, cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu
Adds timeout-cycle fields and resolves validated environment overrides. Dispatch and combine polling use the selected budgets.
Warmup-state operator integration
cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp
Adds atomic warmup-state storage, registers moe_a2a_set_warmup, and selects timeout cycles for dispatch and combine.
Engine warmup and capture orchestration
tensorrt_llm/_torch/pyexecutor/model_engine.py, tests/unittest/_torch/misc/test_moe_a2a_warmup_timeout.py
Updates warmup and CUDA graph capture budget handling. Adds DeepSeek-V4 indexer-Q prewarming and tests for state transitions, capture restoration, and unavailable bindings.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PyTorchModelEngine
  participant moe_a2a_set_warmup
  participant moeA2AGetTimeoutCycles
  participant DispatchCombineKernels
  PyTorchModelEngine->>moe_a2a_set_warmup: update warmup state
  DispatchCombineKernels->>moeA2AGetTimeoutCycles: resolve timeout budget
  moeA2AGetTimeoutCycles->>DispatchCombineKernels: return timeout_cycles
  DispatchCombineKernels->>DispatchCombineKernels: poll completion flags
Loading

Suggested reviewers: barry-delaney, allisonlim-nv, mikeiovine

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the required NVBugs and type format and clearly describes the phase-aware MoE all-to-all timeout fix.
Description check ✅ Passed The description clearly explains the problem, solution, configuration, testing, and reviewer considerations using the required sections.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h (1)

166-173: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use Doxygen for the public timeout resolver.

Line 173 declares a new public interface. Replace the free-form comment with Doxygen that documents is_warmup and the returned cycle budget.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h` around
lines 166 - 173, Replace the free-form comment above moeA2AGetTimeoutCycles with
a Doxygen comment documenting the is_warmup parameter and the returned timeout
budget in clock64() cycles, while preserving the existing behavioral context and
environment-variable references.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tensorrt_llm/_torch/pyexecutor/model_engine.py`:
- Around line 303-315: Import Iterator and update
_moe_a2a_steady_state_budget_for_capture with an Iterator[None] return
annotation, preserving its existing context-manager behavior and cleanup logic.
- Around line 1440-1453: The prewarm block around
indexer._project_and_quantize_q currently suppresses all exceptions; narrow it
to catch only the CuTe JIT-specific failure type used for compilation misses.
Let RuntimeError and other configuration or execution exceptions propagate,
while preserving the existing warning for the expected prewarm miss.

In `@tests/unittest/_torch/misc/test_moe_a2a_warmup_timeout.py`:
- Around line 37-45: Add a test case alongside test_missing_op_is_tolerated that
mocks model_engine.torch.ops.trtllm.moe_a2a_set_warmup to raise RuntimeError,
then calls model_engine._set_moe_a2a_warmup(True) and verifies it does not
raise, covering the incompatible dispatcher binding path.

---

Nitpick comments:
In `@cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h`:
- Around line 166-173: Replace the free-form comment above
moeA2AGetTimeoutCycles with a Doxygen comment documenting the is_warmup
parameter and the returned timeout budget in clock64() cycles, while preserving
the existing behavioral context and environment-variable references.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 407ab46b-7e6b-4d2d-803c-f97b65553e27

📥 Commits

Reviewing files that changed from the base of the PR and between f12c5e5 and 8c7b85e.

📒 Files selected for processing (5)
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.cu
  • cpp/tensorrt_llm/kernels/communicationKernels/moeAlltoAllKernels.h
  • cpp/tensorrt_llm/thop/moeAlltoAllOp.cpp
  • tensorrt_llm/_torch/pyexecutor/model_engine.py
  • tests/unittest/_torch/misc/test_moe_a2a_warmup_timeout.py

@xwang233

xwang233 commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@xwang233
xwang233 marked this pull request as draft August 6, 2026 20:47
@xwang233
xwang233 marked this pull request as ready for review August 6, 2026 20:47
…eout phase-aware

The MoE all-to-all dispatch/combine kernels wait for every peer's completion
flag under a hardcoded ~300 s device-side deadline and execute `trap;` when it
expires, poisoning the CUDA context of every waiting rank.

No collective separates a rank's first-touch JIT/autotune work from its dispatch
launch, so that device-side budget is in effect a deadline on the slowest peer's
*host-side* progress through its first forward. During startup warmup a rank can
legitimately spend minutes in one-time work (CuTe DSL compilation, autotuning,
module loading). When it does, its peers trap, and a survivable slow start
becomes a fatal crash for the whole worker.

Changes:

* The completion-flag budget becomes a runtime value carried in the kernel
  params instead of a compile-time constant, resolved by
  `moeA2AGetTimeoutCycles()`. Steady state is unchanged at 300 s; warmup uses
  1800 s, matching the order of magnitude of torch.distributed's default
  collective timeout. Both are overridable via `TRTLLM_MOE_A2A_TIMEOUT_SEC` and
  `TRTLLM_MOE_A2A_WARMUP_TIMEOUT_SEC`.
* A new `trtllm::moe_a2a_set_warmup` op lets the engine select the phase. It is
  driven from the `is_warmup` setter, the single choke point every warmup
  transition passes through, so the elevated budget cannot latch on into steady
  state. Missing-op builds degrade to the previous behaviour.
* CUDA-graph capture is wrapped so graphs bake in the steady-state budget; the
  timeout is a launch argument and would otherwise be frozen at warmup's value
  for the life of the process.
* The DSv4 indexer-Q CuTe DSL kernels are pre-compiled before the first
  collective-bearing forward, removing the largest single contributor to the
  skew. This is a partial mitigation: other first-touch compiles sit on the
  all-to-all path itself, which is why the runtime budget is the primary fix.

Validated with fault injection on GB200 and GB300: delaying one rank by 600 s
inside the first warmup forward reproduces the reported signature (N-1 peers
timing out in dispatch, all naming the delayed rank) under the old 300 s budget,
and starts cleanly under the new warmup budget.

Signed-off-by: Wang, Xiao <24860335+xwang233@users.noreply.github.com>
@xwang233
xwang233 force-pushed the xiaow/nvbug6482566-moe-a2a-warmup-timeout branch from 0cd9e53 to 82db459 Compare August 6, 2026 21:15
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@xwang233 xwang233 closed this Aug 6, 2026
@xwang233 xwang233 reopened this Aug 6, 2026

@leslie-fang25 leslie-fang25 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@longlee0622

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64423 [ run ] triggered by Bot. Commit: 916b2ac Link to invocation

@longlee0622 longlee0622 added the Release Blocker PRs that blocking the final release build or branching out the release branch label Aug 7, 2026
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64423 [ run ] completed with state FAILURE. Commit: 916b2ac
/LLM/main/L0_MergeRequest_PR pipeline #52303 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@longlee0622

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64504 [ run ] triggered by Bot. Commit: 916b2ac Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64504 [ run ] completed with state FAILURE. Commit: 916b2ac
/LLM/main/L0_MergeRequest_PR pipeline #52378 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@longlee0622

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64558 [ run ] triggered by Bot. Commit: 916b2ac Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64558 [ run ] completed with state FAILURE. Commit: 916b2ac
/LLM/main/L0_MergeRequest_PR pipeline #52428 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@pcastonguay

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64598 [ run ] triggered by Bot. Commit: 8051b69 Link to invocation

@pcastonguay pcastonguay added ci: post-merge approved Approved by TRT-LLM CI approvers for broad post-merge CI requests ci: full pre-merge approved labels Aug 7, 2026
@pcastonguay

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@pcastonguay

Copy link
Copy Markdown
Collaborator

Another rebase to pick up the pre-merge CI fix.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64647 [ run ] triggered by Bot. Commit: 31520e9 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64598 [ run ] completed with state ABORTED. Commit: 8051b69

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64647 [ run ] completed with state FAILURE. Commit: 31520e9
/LLM/main/L0_MergeRequest_PR pipeline #52508 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@xwang233

xwang233 commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast --reuse-test

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64712 [ run ] triggered by Bot. Commit: 31520e9 Link to invocation

@xwang233
xwang233 enabled auto-merge (squash) August 7, 2026 22:48
@longlee0622

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64744 [ run ] triggered by Bot. Commit: 31520e9 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64712 [ run ] completed with state ABORTED. Commit: 31520e9
/LLM/main/L0_MergeRequest_PR pipeline #52567 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #64744 [ run ] completed with state SUCCESS. Commit: 31520e9
/LLM/main/L0_MergeRequest_PR pipeline #52596 completed with status: 'SUCCESS'

CI Report

Link to invocation

@xwang233
xwang233 merged commit 6ba3de1 into NVIDIA:main Aug 8, 2026
8 checks passed
chenfeiz0326 added a commit to chenfeiz0326/TensorRT-LLM that referenced this pull request Oct 13, 2026
…main

_prewarm_cute_dsl_indexer_q (NVIDIA#17376) imports DeepseekV4Indexer from
attention_backend.sparse.deepseek_v4.deepseek_v4, a module the attention
consolidation (NVIDIA#17968) moved to attention.backends.sparse.deepseek_v4.indexer.
The ImportError is caught, so the phase has returned without compiling
anything since then, on every model. Removing it changes no behaviour.

The kernels it targeted are still compiled during warmup: the indexer-Q
runner (CuteDSLIndexerQBlackwellRunner) goes through the autotuner, which
compiles its tactics in-process on every startup. JIT prefetch does not
build them. The rest of NVIDIA#17376 (the phase-aware MoE all-to-all timeout) is
unchanged.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: chenfeiz0326 <203214996+chenfeiz0326@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci: full pre-merge approved ci: post-merge approved Approved by TRT-LLM CI approvers for broad post-merge CI requests Release Blocker PRs that blocking the final release build or branching out the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants